home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 735 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: tbj.dec.com!diamond
  2. From: diamond@tbj.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c
  4. Subject: Re: offsetof() and `address constant expression': LONG
  5. Date: 13 Apr 1996 01:32:46 GMT
  6. Organization: Digital Equipment Corporation Japan , Tokyo
  7. Message-ID: <4kn07u$fqf@usenet.pa.dec.com>
  8. References: <4kk988$rt2@falcon.ccs.uwo.ca>
  9. Reply-To: diamond@tbj.dec.com (Norman Diamond)
  10. NNTP-Posting-Host: jit533.tbj.dec.com
  11.  
  12. In article <4kk988$rt2@falcon.ccs.uwo.ca>, Dave Kinchlea
  13. <kinch@julian.uwo.ca> writes 100 lines more than this:
  14. >Seems pretty clear that the use below does not fit this description
  15. >[arguments to offsetof] but I would like some confirmation before I
  16. >send this back to the author.  [...]
  17. >ICELLS is a macro (100) and cells is an integer.
  18.  
  19. Sounds like you already got it:
  20.  
  21. >On Thu, 11 Apr 1996, Roger Glover wrote:
  22. >>> bp = (Block*) malloc(offsetof(Block, cell[ICELLS + cells]));
  23. >> Plauger and Brodie's "Standard C Quick Reference" [...] says [...]
  24. >>         #define offsetof(s-type,mbr)  <size_t constant expression>
  25. >>     The macro yields the offset in bytes of member mbr from the beginning
  26. >>     of structure type s-type, where for X of type s-type, &X.mbr is an
  27. >>     address constant expression.
  28.  
  29. Looks like Plauger and Brodie forgot to say *static* X of type s-type.
  30. However, they got the rest of it right.
  31.  
  32. >> Well let's break that down a bit.  &X.mbr must be constant,
  33.  
  34. Yes.  And the standard's section on constant expressions, paragraph on
  35. address constants, says:  "[...] but the value of an object shall not be
  36. accessed by one of these operators."  So the + operator which accesses
  37. the value of cells does not yield a constant expression.
  38. --
  39.  <<  If this were the company's opinion, I would not be allowed to post it.  >>
  40. "I paid money for this car, I pay taxes for vehicle registration and a driver's
  41. license, so I can drive in any lane I want, and no innocent victim gets to call
  42. the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
  43.